package com.work.straighttalk.ui;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.work.straighttalk.FriendsCircleActivity;
import com.work.straighttalk.R;
import com.work.straighttalk.app.BaseActivity;
import com.work.straighttalk.presenter.LoginPImpl;
import com.work.straighttalk.presenter.i.LoginPI;
import com.work.straighttalk.ui.i.LoginVI;
import com.work.straighttalk.utils.ProgressGenerator;
import com.work.straighttalk.view.ActionProcessButton;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.exception.BmobException;

/**
 * Created by dllo on 16/3/1.
 */
public class LoginActivity extends BaseActivity implements LoginVI, ProgressGenerator.OnCompleteListener {

    @Bind(R.id.et_username)
    EditText etUsername;
    @Bind(R.id.et_password)
    EditText etPassword;
    @Bind(R.id.tv_register)
    TextView tvRegister;

    @Bind(R.id.btn_login)
    ActionProcessButton btnLogin;
    private LoginPI loginPI;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        loginPI = new LoginPImpl(this);
    }

    @OnClick(R.id.btn_login)
    public void onLoginClick(View view) {
        loginPI.validateLogin(etUsername.getText().toString(), etPassword.getText().toString());
        btnLogin.setProgress(50);
    }

    @OnClick(R.id.tv_register)
    public void onRegisterClick(View view) {
        startActivity(SMSActivity.class, null, true);
    }

    @Override
    public void showProgress() {
    }

    @Override
    public void hideProgress() {
    }

    @Override
    public void error(BmobException e) {
        btnLogin.setProgress(-1);
        toast(e.getMessage() + "(" + e.getErrorCode() + ")");
    }

    @Override
    public void toMainActivity() {
        startActivity(FriendsCircleActivity.class, null, true);
//        startActivity(MainActivity.class, null, true);
//        startActivity(VideoCallActivity.class,null,true);
        startActivity(MainActivity.class, null, true);
    }

    @Override
    protected void onDestroy() {
        loginPI.onDestroy();
        super.onDestroy();
    }

    @Override
    public void onComplete() {

    }
}
